<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>IMDb 电影</title>

    <!-- 引入样式 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

    <style>
        body {
            background-color: #343434;
            margin-top: 0;
        }

        .el-carousel__item h3 {
            color: #475669;
            font-size: 14px;
            opacity: 0.75;
            line-height: 200px;
        }

        .el-carousel__item:nth-child(2n) {
            background-color: #99a9bf;
        }

        .el-carousel__item:nth-child(2n+1) {
            background-color: #d3dce6;
        }

        .grid-content {
            height: 80px;
            background-color: #475669;
            margin-top: 0px;
            margin-bottom: 15px;
        }

        .grid-content {
            border-radius: 4px;
            min-height: 36px;
            justify-content: center;
            text-align: center;
            line-height: 80px;

        }

        .search-box {
            position: relative;
            text-align: center;
        }

        .el-form {
            position: relative;
            line-height: 80px;
            top: 21px;
        }

        .el-form .el-form-item__label {
            color: white !important;
        }

        .my-search {
            position: absolute;
            right: 10px;
            top: 34px;
            cursor: pointer;
        }

        .logo {
            width: 40%;
            height: 50px;
            position: relative;
            line-height: 80px;
            top: 15px;
        }

        .Top250Movies {
            margin-top: 20px;
            color: white;

        }

        .Top250Movies .title {
            display: inline-block;
            font-size: 20px;
            margin-left: 20px;
            cursor: pointer
        }

        .top200-image-box {
            margin-top: 10px;
        }

        .top200-image {
            margin: 3px;

        }

        .top200-image .image {
            width: 100%;
        }

        .el-card__body, .el-main {
            padding: 5px;
        }

        .grade-box {
            display: inline-block;
            height: 20px;
            line-height: 20px;
        }

        .grade-box div {
            display: inline-block;
            text-align: center;
            line-height: 20px;
        }

        .grade-box .score {
            display: inline-block;
            color: #000000;
            position: absolute;
            line-height: 20px;
        }

        .grade-box img {
            width: 20px;
            height: 20px;
        }

        .top200-image .title {
            font-size: 18px;
            font-weight: 500;
            margin-left: 5px;
            height: 50px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        .Top250MoviesBar {
            margin: 0 !important;
        }

        .prv-top250 {
            display: inline-block;
            cursor: pointer
        }

        .next-top250 {
            display: inline-block;
            cursor: pointer
        }

        .top250-page {
            display: inline-block;
            margin-left: 20px;
        }

        .top-tab div {
            display: inline-block;
            color: white;

            cursor: pointer;
            margin-left: 20px;
        }


        .top-tab div a {
            text-decoration: none; /* 去除默认的下划线 */
            color: white; /* 去除默认的颜色和点击后变化的颜色 */

        }


        .top-tab div a:hover {
            color: yellow;
            font-size: 20px;
        }


    </style>
<body>
<div id="box">

    <el-row>
        <el-col :span="24">
            <div class="grid-content bg-purple-dark">
                <el-row>
                    <el-col :span="8">
                        <div class="grid-content">
                            <img src="/static/img/logo.png" class="logo">
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="grid-content search-box">

                            <el-form ref="form" :model="form" label-width="80px">
                                <el-form-item label="电影搜索:">
                                    <el-input v-model="form.search_value" placeholder="请用英文搜索"></el-input>
                                </el-form-item>
                            </el-form>

                            <i class="el-icon-search my-search" @click="search"></i>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="grid-content top-tab">
                            <div><a href="/"> <i class="el-icon-s-home"> </i> 首页 </a></div>

                        </div>
                    </el-col>
                </el-row>
            </div>
        </el-col>
    </el-row>

    <template>
        <el-carousel :interval="4000" type="card" height="350px">
            <el-carousel-item v-for="(item,index) in posters" :key="index">
                <a :href="'/detail/'+ item.id">
                    <el-image
                            style="width: 100%;height: 100%;"
                            :src="item.posters"
                            fit="cover">
                    </el-image>
                </a>
            </el-carousel-item>
        </el-carousel>
    </template>
    <!--    Top250Movies -->
    <div class="Top250Movies">
        <el-row :gutter="20" class="Top250MoviesBar">
            <el-col :span="8">
                <div class="title">TOP250电影</div>
                <i class="el-icon-d-arrow-right"></i>
            </el-col>
            <el-col :span="6" :offset="9">
                <div class="prv-top250  top250-page" @click='get_top250(top250_current_page-1)'><i
                        class="el-icon-arrow-left"></i></div>
                <div class="page-top250 top250-page"> {[top250_current_page]}/{[top250_total_page]}</div>
                <div class="next-top250 top250-page" @click='get_top250(top250_current_page+1)'><i
                        class="el-icon-arrow-right"></i></div>
            </el-col>
        </el-row>
        <el-row class="top200-image-box">
            <el-col :span="3" v-for="(o, index) in top200Data" :key="o">
                <el-card class="top200-image">

                    <a :href="'/detail/'+ o.id">
                        <img :src="o.image" class="image">
                        <div class="form-group clearfix">
                            <div class="grade-box">
                                <my_rate :myon="get_myon_or_myoff(o.imDbRating,'myon')"
                                         :myoff="get_myon_or_myoff(o.imDbRating,'myoff')"></my_rate>
                                <div class="score">{[o.imDbRating]}</div>
                            </div>
                            <div class="title">
                                {[o.title]}
                            </div>
                        </div>
                    </a>
                </el-card>
            </el-col>
        </el-row>

    </div>


    <div class="Top250Movies">
        <el-row :gutter="20" class="Top250MoviesBar">
            <el-col :span="8">
                <div class="title">最受欢迎电影</div>
                <i class="el-icon-d-arrow-right"></i>
            </el-col>
            <el-col :span="6" :offset="9">
                <div class="prv-top250  top250-page"
                     @click='get_MostPopularMovies(MostPopularMoviesData_current_page-1)'><i
                        class="el-icon-arrow-left"></i></div>
                <div class="page-top250 top250-page">
                    {[MostPopularMoviesData_current_page]}/{[MostPopularMoviesData_total_page]}
                </div>
                <div class="next-top250 top250-page"
                     @click='get_MostPopularMovies(MostPopularMoviesData_current_page+1)'>
                    <i
                            class="el-icon-arrow-right"></i></div>
            </el-col>
        </el-row>
        <el-row class="top200-image-box">
            <el-col :span="3" v-for="(o, index) in MostPopularMoviesData" :key="o">
                <el-card class="top200-image">
                    <a :href="'/detail/'+ o.id">
                        <img :src="o.image" class="image">
                        <div class="form-group clearfix">
                            <div class="grade-box">
                                <my_rate :myon="get_myon_or_myoff(o.imDbRating,'myon')"
                                         :myoff="get_myon_or_myoff(o.imDbRating,'myoff')"></my_rate>
                                <div class="score">{[o.imDbRating]}</div>
                            </div>
                            <div class="title">
                                {[o.title]}
                            </div>
                        </div>
                    </a>
                </el-card>
            </el-col>
        </el-row>
    </div>


    <div class="Top250Movies">
        <el-row :gutter="20" class="Top250MoviesBar">
            <el-col :span="8">
                <div class="title">即将上映</div>
                <i class="el-icon-d-arrow-right"></i>
            </el-col>
            <el-col :span="6" :offset="9">
                <div class="prv-top250  top250-page"
                     @click='get_ComingSoonData(ComingSoonData_current_page-1)'><i
                        class="el-icon-arrow-left"></i></div>
                <div class="page-top250 top250-page">
                    {[ComingSoonData_current_page]}/{[ComingSoonData_total_page]}
                </div>
                <div class="next-top250 top250-page"
                     @click='get_ComingSoonData(ComingSoonData_current_page+1)'>
                    <i
                            class="el-icon-arrow-right"></i></div>
            </el-col>
        </el-row>
        <el-row class="top200-image-box">
            <el-col :span="3" v-for="(o, index) in ComingSoonData" :key="o">
                <el-card class="top200-image">

                    <a :href="'/detail/'+ o.id">
                        <img :src="o.image" class="image">
                        <div class="form-group clearfix">
                            <div class="grade-box">
                                <my_rate :myon="get_myon_or_myoff(o.imDbRating,'myon')"
                                         :myoff="get_myon_or_myoff(o.imDbRating,'myoff')"></my_rate>
                                <div class="score">{[o.imDbRating]}</div>
                            </div>
                            <div class="title">
                                {[o.title]}
                            </div>
                        </div>
                    </a>
                </el-card>
            </el-col>
        </el-row>
    </div>


</div>
</body>


<script src="/static/js/axios.js"></script>
<script src="/static/js/qs.js"></script>


<script>

    Vue.component('my_rate', {
        data: {},
        delimiters: ['{[', ']}'],
        mounted() {
        },
        props: ['myon', "myoff"],
        template: '<div><img  v-for="i in myon" src="/static/img/x1.png"/><img v-for="i in myoff" src="/static/img/x2.png"/></div> '
    });


    const vm = new Vue(
        {
            el: "#box",
            delimiters: ['{[', ']}'],
            data: {

                posters: [],
                this_localhost: "",
                form: {
                    search_value: ""
                },
                top250_current_page: 0,
                top250_total_page: 0,
                top200Data: [],
                MostPopularMoviesData: [],
                MostPopularMoviesData_current_page: 0,
                MostPopularMoviesData_total_page: 0,

                ComingSoonData: [],
                ComingSoonData_current_page: 0,
                ComingSoonData_total_page: 0,

            }, created() {
                this.get_top250(1) //获取top250第一页数据
                this.get_MostPopularMovies(1)//获取最受欢迎第一页数据
                this.get_ComingSoonData(1)
            },

            mounted() {
                this.this_localhost = document.location.protocol + "//" + location.host;

                this.get_posters();

            },

            methods: {
                get_posters() {
                    console.log(this.this_localhost)
                    var url = this.this_localhost + "/posters"
                    // 基本用法
                    var _this = this
                    axios.get(url).then((res) => {
                        // 请求成功 会来到这  res响应体
                        _this.posters = res["data"]
                    }).catch((err) => {
                        // 请求失败 会来到这  处理err对象
                        console.log("请求异常");
                        console.log(err)
                    })

                },
                get_top250(page) {
                    var url = this.this_localhost + "/get_top250?page=" + page
                    var _this = this
                    axios.get(url).then((res) => {
                        // 请求成功 会来到这  res响应体
                        var data = res["data"]
                        _this.top200Data = data["data"];
                        _this.top250_current_page = data["cur_page"];
                        _this.top250_total_page = data["total_page"]

                        console.log(_this.top200Data)
                        console.log(_this.top250_current_page)
                        console.log(_this.top250_total_page)
                    }).catch((err) => {
                        // 请求失败 会来到这  处理err对象
                        console.log("请求异常");
                        console.log(err)
                    })
                }, get_MostPopularMovies(page) {
                    var url = this.this_localhost + "/get_MostPopularData?page=" + page
                    var _this = this
                    axios.get(url).then((res) => {
                        // 请求成功 会来到这  res响应体
                        var data = res["data"]
                        _this.MostPopularMoviesData = data["data"];
                        _this.MostPopularMoviesData_current_page = data["cur_page"];
                        _this.MostPopularMoviesData_total_page = data["total_page"]

                    }).catch((err) => {
                        // 请求失败 会来到这  处理err对象
                        console.log("请求异常");
                        console.log(err)
                    })
                }, get_ComingSoonData(page) {
                    var url = this.this_localhost + "/get_ComingSoon?page=" + page
                    var _this = this
                    axios.get(url).then((res) => {
                        // 请求成功 会来到这  res响应体
                        var data = res["data"]
                        _this.ComingSoonData = data["data"];
                        _this.ComingSoonData_current_page = data["cur_page"];
                        _this.ComingSoonData_total_page = data["total_page"]

                    }).catch((err) => {
                        // 请求失败 会来到这  处理err对象
                        console.log("请求异常");
                        console.log(err)
                    })
                }, search() {
                    var search_value = this.form.search_value;
                    if (!search_value) {
                        return
                    } else {
                        window.location.href = "/search?search_value=" + search_value
                    }
                },
                get_myon_or_myoff(score, k) {
                    var myon = 0
                    var myoff = 0
                    if (score <= 0) {
                        myon = 0
                        myoff = 5
                    } else if (score < 2) {
                        myon = 1
                        myoff = 4

                    } else if (score < 4) {
                        myon = 2
                        myoff = 3
                    } else if (score < 6) {
                        myon = 3
                        myoff = 2
                    } else if (score < 8) {
                        myon = 4
                        myoff = 1
                    } else if (score <= 10) {
                        myon = 5
                        myoff = 0
                    }
                    console.log(typeof (score), myon, myoff);
                    if (k === "myon") {
                        return myon
                    } else {
                        return myoff
                    }
                }


            }
        })

</script>

</html>